// *************************************************************************
//
//                                JOST
//
//               Copyright (C) 2007 by Angelo Corsaro.
//                       <angelo.corsaro@gmail.com>
//                          All Rights Reserved.
//
//   Permission to use, copy, modify, and distribute this software and
//   its  documentation for any purpose is hereby  granted without fee,
//   provided that the above copyright notice appear in all copies and
//   that both that copyright notice and this permission notice appear
//   in  supporting  documentation. I don't make  any  representations
//   about the  suitability  of this  software for any  purpose. It is
//   provided "as is" without express or implied warranty.
//
//
// *************************************************************************
//  
// *************************************************************************
#ifndef _JOST_PARSER_H_
#define _JOST_PARSER_H_

#include <fstream>
#include <string>
#include "jost/jost.hpp"

namespace jost 
{
    class Parser;
}


/**
 * The <code>Parser</code> is a singleton class that provides a
 * wrapper over the functionalities provided by Spirit and JOST core
 * classes for parsing JSON Objects.<br>
 * 
 * JSON Objects might be provided as <code>std::string</code> or as
 * <code>std::istream</code>.
 *
 * @author Angelo Corsaro <mailto:angelo.corsaro@gmail.com>
 * @version 0.1
 */
class jost::Parser 
{
public:
    /**
     *
     */
    static Parser&
    instance() throw();

    /**
     * Parse an <code>Object</code> from a <code>std::string</code>
     *
     * @param stream the JSON object stream
     * @return the parsed <code>Object</code>
     * @exception jost::MalformedJSONStream in case the stream is
     * malformed.
     */ 
    jost::Object*
    parse(const std::string& stream)
       throw (jost::MalformedJSONStream);

    /**
     * Parse an <code>Object</code> from a <code>std::istream</code>
     *
     * @param stream the JSON object stream
     * @return the parsed <code>Object</code>
     * @exception jost::MalformedJSONStream in case the stream is
     * malformed.

     */ 
    jost::Object*
    parse(std::istream& stream)
       throw (jost::MalformedJSONStream);

    /**
     * Parse an <code>Object</code> from a <code>const char*</code>
     *
     * @param stream the JSON object stream
     * @return the parsed <code>Object</code>
     * @exception jost::MalformedJSONStream in case the stream is
     * malformed.

     */ 
    jost::Object*
    parse(const char* stream)
       throw (jost::MalformedJSONStream);
    
private:
    Parser();
    Parser(const Parser&);
    Parser operator=(const Parser&);
    ~Parser();

private:
    jost::json_parser json_;
};

    
#endif /*_JOST_PARSER_H_*/
